﻿Public Class address
    Private Sub address_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Updatetable()
        Dim btn As New DataGridViewButtonColumn()
        DataGridView1.Columns.Add(btn)
        btn.HeaderText = ""
        btn.Text = "Редактировать"
        btn.Name = "edit"
        btn.UseColumnTextForButtonValue = True

        Dim btn2 As New DataGridViewButtonColumn()
        DataGridView1.Columns.Add(btn2)
        btn2.HeaderText = ""
        btn2.Text = "Удалить"
        btn2.Name = "del"
        btn2.UseColumnTextForButtonValue = True

        With DataGridView1
            .Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            .Columns(0).ReadOnly = True
        End With
    End Sub
    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        ' MsgBox(DataGridView1.Columns("btn2").Index)
        If e.ColumnIndex = DataGridView1.Columns("del").Index Then
            My.Settings.Set_address.Rows(e.RowIndex).Delete()
            My.Settings.Save()
            Updatetable()
        End If
        If e.ColumnIndex = DataGridView1.Columns("edit").Index Then
            Edit_delivery.rowindex.Text = e.RowIndex
            Edit_delivery.Show()
            Me.Close()
        End If
    End Sub
    Private Sub Updatetable()
        Dim dt As New DataTable()
        dt.Columns.Add("Имя Рассылки", GetType(String))
        For i = 1 To My.Settings.Set_address.Rows.Count
            dt.Rows.Add(My.Settings.Set_address.Rows(i - 1).Item(0))
        Next i
        Me.DataGridView1.DataSource = dt
        DataGridView1.Update()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        My.Settings.Set_address.Rows.Add("Новая рассылка", False, False, False, False, False, False, False, False, False, "", "", "", "", "")
        My.Settings.Save()
        Updatetable()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Close()
        start.TopMost = True
        start.TopMost = False
    End Sub
End Class